package com.liu.fresh.biz.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.liu.fresh.biz.IOrderItemInfoBiz;
import com.liu.fresh.entity.OrderItemInfo;
import com.liu.fresh.mapper.IOrderItemInfoMapper;
import com.liu.fresh.util.StringUtil;

@Service
public class OrderItemInfoBizImpl implements IOrderItemInfoBiz {
	@Autowired
	private IOrderItemInfoMapper mapper;

	@Override
	public Integer addOrderItemInfo(String ono, int[] gnos, int[] nums, int[] prices) {
		if(StringUtil.checkNull(ono,gnos,nums,prices)){
			return 0;
		}

			List<OrderItemInfo> list = new ArrayList<OrderItemInfo>();
			for(int i=0;i<gnos.length;i++){
				
				list.add(new OrderItemInfo(ono,gnos[i],nums[i],prices[i]));

			}			System.out.println(list);
					return mapper.addOrderItemInfo(list);
		
		
		
		
		
		
	/*	
		//SqlSessionFactory sqlSessionFactory = getSqlSessionFactory();
		//SqlSession openSession = sqlSessionFactory.openSession();
		try {
			EmpMapper mapper = openSession.getMapper(EmpMapper.class);
			List<Emp> empList = new ArrayList<Emp>();
			empList.add(new Emp(null,"Lizy","Lizy@sina.com",3));
			mapper.batchSave(empList);
			//别忘了事务最后要提交
			openSession.commit();
		} finally {
			openSession.close();
		}*/
	
		

	

		
		/*Map<String, Object> map = new HashMap<String, Object>();
		int result=0;
		map.put("ono", ono);
		for(int i=0;i<gnos.length;i++){
			map.put("gno", gnos[i]);
			map.put("nums", nums[i]);
			map.put("price", prices[i]);
			System.out.println("map:"+map);
			result+=mapper.addOrderItemInfo(map);
		}
		return result;*/
	}
	

	

}
